package benchmarks.tpcc;

import api.BenchmarkModule;
import api.Configuration;
import api.Terminal;
import benchmarks.tpcc.mongo.TPCCWorkerMongo;
import benchmarks.tpcc.mysql.TPCCWorkerMySQL;
import benchmarks.tpcc.redis.TPCCWorkerRedis;

public class TPCCTerminal extends Terminal {
    protected int terminalWarehouseID;
    protected int terminalDistrictLowerID;
    protected int terminalDistrictUpperID;
    protected int numWarehouses;
    public TPCCTerminal(BenchmarkModule benchmarkModule, Configuration config, int id) {
        super(benchmarkModule, config, id);
        terminalWarehouseID = id;
        //TODO unsafe
        numWarehouses = (int) Math.ceil(config.getScaleFactor());
        terminalDistrictLowerID = TPCCConfig.configDistrictPerWarehouse * (terminalWarehouseID);
        terminalDistrictUpperID = TPCCConfig.configDistrictPerWarehouse * (terminalWarehouseID + 1);
        if (benchmarkModule.getDatabaseName().equals(BenchmarkModule.MongoName)) {
            worker = new TPCCWorkerMongo(config, terminalWarehouseID,
                    terminalDistrictLowerID, terminalDistrictUpperID, numWarehouses);
        } else if (benchmarkModule.getDatabaseName().equals(BenchmarkModule.MySqlName)) {
            worker = new TPCCWorkerMySQL(config, terminalWarehouseID,
                    terminalDistrictLowerID, terminalDistrictUpperID, numWarehouses);
        } else if (benchmarkModule.getDatabaseName().equals(BenchmarkModule.RedisName)) {
            worker = new TPCCWorkerRedis(config, terminalWarehouseID,
                    terminalDistrictLowerID, terminalDistrictUpperID, numWarehouses);
        }
    }
}
